package com.pronosticnews.server.domain.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import fr.ysa.persistence.Entity;

@javax.persistence.Entity
public class User implements Entity {

	private static final long serialVersionUID = 6166767400863640800L;

	public static enum VALUE_NAME {
		id, login, mail, nom, password, prenom
	}
	
	// constructors
	public User() {
		initialize();
	}

	public User(java.lang.Integer id) {
		this.setId(id);
		initialize();
	}

	public User(java.lang.Integer id, java.lang.String login,
			java.lang.String password, java.lang.String mail) {

		this.setId(id);
		this.setLogin(login);
		this.setPassword(password);
		this.setMail(mail);
		initialize();
	}

	protected void initialize() {
	}

	@Transient
	private int hashCode = Integer.MIN_VALUE;

	// primary key
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)	
	private java.lang.Integer id;

	private java.lang.String login;
	
	private java.lang.String password;

	private java.lang.String nom;

	private java.lang.String prenom;

	private java.lang.String mail;

	private float gain;
	
	@OneToMany(fetch=FetchType.EAGER)
	private Set<Role> roles;
	

	public java.lang.Integer getId() {
		return id;
	}

	public void setId(java.lang.Integer id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}

	public java.lang.String getLogin() {
		return login;
	}

	public void setLogin(java.lang.String login) {
		this.login = login;
	}

	public java.lang.String getPassword() {
		return password;
	}

	public void setPassword(java.lang.String password) {
		this.password = password;
	}

	public java.lang.String getNom() {
		return nom;
	}

	public void setNom(java.lang.String nom) {
		this.nom = nom;
	}

	public java.lang.String getPrenom() {
		return prenom;
	}

	public void setPrenom(java.lang.String prenom) {
		this.prenom = prenom;
	}

	public java.lang.String getMail() {
		return mail;
	}

	public void setMail(java.lang.String mail) {
		this.mail = mail;
	}

	public boolean equals(Object obj) {
		if (null == obj)
			return false;
		if (!(obj instanceof User))
			return false;
		else {
			User user = (User) obj;
			if (null == this.getId() || null == user.getId())
				return false;
			else
				return (this.getId().equals(user.getId()));
		}
	}

	public int hashCode() {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getId())
				return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":"
						+ this.getId().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}

	public String toString() {
		return super.toString();
	}

	public float getGain() {
		return gain;
	}

	public void setGain(float gain) {
		this.gain = gain;
	}
	
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@Override
	public List<String> getColumnNameValues() {
		List<String> list = new ArrayList<String>();
		for (VALUE_NAME value : VALUE_NAME.values()) {
			list.add(value.name());
		}
		return list;
	}

}